#include "OpenALWrapper.h"


COpenAL::COpenAL()
{
	this->m_device	= NULL;
	this->m_context	= NULL;

	ALCenum errors;

	this->m_deviceName = (char*) alcGetString(NULL, ALC_DEVICE_SPECIFIER);

	this->m_device = alcOpenDevice(this->m_deviceName);

	if (this->m_device)
	{
		this->m_context = alcCreateContext(this->m_device, NULL);
		alcMakeContextCurrent(this->m_context);
	}

	errors = alcGetError(this->m_device);
}

COpenAL::~COpenAL()
{
	alcCloseDevice(this->m_device);
	alcDestroyContext(this->m_context);
	alcMakeContextCurrent(NULL);
}

bool COpenAL::GenerateBuffers(ALsizei _bufferNum, ALuint *_buffers)
{
	alGenBuffers(_bufferNum, _buffers);

	if (alGetError() != AL_NO_ERROR)
		return false;

	return true;
}

bool COpenAL::GenerateSources(ALsizei _sourceNum, ALuint *_sources)
{
	alGenSources(_sourceNum, _sources);

	if (alGetError() != AL_NO_ERROR)
		return false;

	return true;
}

bool COpenAL::ReleaseBuffers(ALsizei _bufferNum, ALuint *_buffers)
{
	alDeleteBuffers(_bufferNum, _buffers);

	if (alGetError() != AL_NO_ERROR)
		return false;

	return true;
}

bool COpenAL::ReleaseSources(ALsizei _sourceNum, ALuint *_sources)
{
	alDeleteSources(_sourceNum, _sources);

	if (alGetError() != AL_NO_ERROR)
		return false;

	return true;
}